﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace TravelManagement
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSignup_Click(Object sender, EventArgs e)
        {
            try
            {
                if (
                        String.IsNullOrEmpty(txtUserName.Text) ||
                        String.IsNullOrEmpty(txtPassword.Text)
  
                    )
                {
                    return;
                }


                using (TSPGMapsDBContainer entities = new TSPGMapsDBContainer())
                {
                    string userName = (from userTableRow in entities.Users
                                       where userTableRow.UserName == txtUserName.Text
                                       select userTableRow.UserName).SingleOrDefault();

                    if (!String.IsNullOrEmpty(userName))
                    {
                        lblUserNameExists.Visible = true;
                    }
                    else
                    {
                        User userRow = new TravelManagement.User();
                        userRow.UserName = txtUserName.Text.Trim();
                        userRow.Password = txtPassword.Text;


                        entities.AddToUsers(userRow);
                        entities.SaveChanges();

                        Response.Redirect("Login.aspx");
                    }

                }
            }
            catch (Exception ex)
            {

            }
        }
        
    }
}